package com.example.demorocketmq.consumer;


import com.example.demorocketmq.OperationInfo;
import com.example.demorocketmq.ResultObject;
import com.example.demorocketmq.UserInfo;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQReplyListener;
import org.springframework.stereotype.Component;


/**
 * RPC消息
 *
 * 1实现RocketMQReplyListener接口
 * 2申明泛型对象即业务对象
 * 3申明返回泛型的对象
 * 4使用@RocketMQMessageListener注解
 * 5加@Component注解或者子注解
 */
@Component
@RocketMQMessageListener(topic = "${topic.sendAndReceive}",
        consumerGroup = "${group.consumer.sendAndReceiveGeneric}",
        selectorExpression="${tag.syscSendOrderl.generic}")
public class ReceiveGenericConsumer implements RocketMQReplyListener<UserInfo,ResultObject<OperationInfo>>{

    @Override
    public ResultObject<OperationInfo> onMessage(UserInfo message) {
        System.out.println(String.format("consumer name is %s data is %s",this.getClass().getSimpleName(), message));
        OperationInfo operationInfo = new OperationInfo();
        operationInfo.setOperation(message.getOperation());
        operationInfo.setUserInfoId(message.getId().toString());
        operationInfo.setOperationTime(System.currentTimeMillis());
        ResultObject<OperationInfo>  resultObject = new ResultObject<>();
        resultObject.setCode(200);
        resultObject.setMessage("success");
        resultObject.setData(operationInfo);
        return resultObject;
    }

}
